/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package calculador;

/**
 *
 * @author SONY
 */
public class CalculaEmprestimo {
    
    
    
    public Double calculaTaxa(Integer numPrestacoes){
        
        double[] juros = {0.05, 0.065, 0.08, 0.10};
        int[] parcelaMinima= {1, 4, 10, 13};
        int[] parcelaMaxima= {3, 9, 12, 18};
        int valJuros = 0;

        for (int i=0; i<4; i++) {
        if (numPrestacoes >= parcelaMinima[i] && numPrestacoes <= parcelaMaxima[i]){
         valJuros = i;
        }}
      return juros[valJuros];
  }

    
    
    public Double calculaCF(Double valEmprestimo, Integer numPrestacoes){
        Double taxa = calculaTaxa(numPrestacoes);
        Double cf = taxa/(1-(1/(Math.pow((1 + taxa), numPrestacoes))));
        return cf;
    }
    
    public Double calculaValPrestacao(Double valEmprestimo, Double cf){
        return cf * valEmprestimo;
    }
    
    public Double totalPagar(Double valPrestacao, Integer numPrestacoes){
        return numPrestacoes.doubleValue() * valPrestacao;
    }
    
    public Double totalJuros(Double totalPagar, Double valEmprestimo){
        return totalPagar - valEmprestimo;
    }
    
    
    
}
